<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <script src="../res/js/jquery-3.1.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
    <script src="../res/layui/layui.js" charset="utf-8"></script>
    <script>
        $(function(){
            var url="../Two/findById";
            var data={fid:29};
            $.post(url,data,function(obj){
                $("#one").append("鲜花名字:"+obj.fName+" 鲜花ID:"+obj.fId);
            },"json");
        })
    </script>
</head>
<body>
Hello World
<h3 id="one"></h3>
<div class="one">
    <form class="layui-form" action="" id="formDId" lay-filter="example" method="post" enctype="multipart/form-data">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="color: red">*附件1</label>
                <div class="layui-input-inline">
                    <input type="file" name="fileone" id="fileone"  autocomplete="off"
                           class="layui-input">
                    <a id="ts" target="_blank" style="text-decoration:none"></a>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn site-demo-active" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>


</body>
<script type="text/javascript">
    var form=null;
    layui.use('form', function(){
        form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));
            //layer.msg(JSON.stringify(data.field));
            var url="../Two/addOrupdate";
            var formData = new FormData(document.getElementById("formDId"));
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    if(obj.num==1){
                        layer.msg(obj.msg,{
                            icon:1,
                            time:1000 //1秒关闭(如果不配置默认三秒)
                        },function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            parent.layui.table.reload("test");
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            //parent.location.reload();
                        });
                        return false ;
                    }
                },
                error:function(e){
                    layer.msg("错误！！");
                }
            });
            return false;
        });
    });

</script>
</html>